//
//  ViewController.m
//  Homework_17
//
//  Created by 徐昊 on 16/8/5.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createFileManager];
}
- (void)createFileManager {
    NSFileManager *fileManager = [NSFileManager defaultManager];
//    NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [pathArray firstObject];
    NSString *textPath = [documentPath stringByAppendingPathComponent:@"text"];
    NSLog(@"%@", documentPath);
    NSLog(@"%@", textPath);
    // 创建路径
    [fileManager createDirectoryAtPath:textPath withIntermediateDirectories:YES attributes:nil error:nil];
    NSString *text = [textPath stringByAppendingPathComponent:@"hah.txt"];
    NSString *content = @"xuhao";
    NSString *text2 = [textPath stringByAppendingPathComponent:@"hahahaha.txt"];
    NSString *content2 = @"shuai";
    // 创建文件
    [fileManager createFileAtPath:text contents:[content dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
    [fileManager createFileAtPath:text2 contents:[content2 dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
    // 删除文件
//    [fileManager removeItemAtPath:text error:nil];
    // 复制文件后者给前者
    NSError *error;
//    [fileManager copyItemAtPath:text toPath:textPath error:&error];
    // 移动文件
    NSString *text3 = [documentPath stringByAppendingPathComponent:@"text3.txt"];
    if ([fileManager moveItemAtPath:text toPath:text3 error:&error] !=YES) {
        NSLog(@"1%@", [error localizedDescription]);
    }
    
    //9.文件是否存在
    
    if ([[NSFileManager defaultManager]fileExistsAtPath:@"/Users/dlios/Library/Application Support/iPhone Simulator/7.1/Applications/AC7B8788-BDCB-43AC-ABB6-8E9676CF94DC/Documents/testbug/test22333.txt"]) {
        NSLog(@"yes");
    }
    else NSLog(@"no");
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
